package com.zx;

import java.util.Comparator;
import java.util.TreeMap;

/**
 * @ProjectName: ybxy6
 * @Titile: TreeMapDemo
 * @Author: Muelsyse
 * @Description: TODO
 */
public class TreeMapDemo {
   public static void main(String[] args) {
       test1();
       test2();
   }

   public static void test2() {
       TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
           @Override
           public int compare(Student o1, Student o2) {
               return o2.getAge() - o1.getAge();
           }
       });

       treeMap.put(new Student("小赵", 25), "男");
       treeMap.put(new Student("小柯", 19), "女");
       treeMap.put(new Student("小张", 23), "男");
       treeMap.put(new Student("小熊", 21), "女");
       //分界线
       System.out.println("--------------------------------");
       treeMap.forEach((k,v)->System.out.println(k + ":" + v));
   }

    private static void test1() {
        TreeMap<Student,String> treeMap = new TreeMap<>();
        treeMap.put(new Student("小赵", 25), "男");
        treeMap.put(new Student("小柯", 19), "女");
        treeMap.put(new Student("小张", 23), "男");
        treeMap.put(new Student("小熊", 21), "女");
        treeMap.put(new Student("小李", 24), "男");

        treeMap.forEach((k,v)->System.out.println(k + ":" + v));
    }
}
